<?php
require_once('includes/config.php');
require_once('includes/classes/class.template_engine.php');
require_once('includes/functions/func.global.php');
require_once('includes/functions/func.users.php');
session_start();
$config['lang'] = check_user_lang($config);
require_once('includes/lang/lang_'.$config['lang'].'.php');

db_connect($config);
if(checkloggedin())
{
	check_negative_balance($config);

	$password = $_POST['password'];
	$confirm_password = $_POST['confirm_password'];
	$id = $_SESSION['user']['id'];
	if($_SESSION['user']['type'] == 'provider')
	{
			
			$error = 0;
			$error_msg = array();			
			$email_info = mysql_fetch_row(mysql_query("SELECT provider_id FROM ".$config['db']['pre']."providers WHERE provider_id='".$_SESSION['user']['id']."' LIMIT 1"));
			if(!isset($email_info[0]))
			{
				$error++;
				$error_msg[] = '';
			}
			//echo "$error";exit();
			if($error > 0)
			{
				message($lang['ERROR_CHANGE_PASSWORD'], $config,$lang, 'profile_edit.php');
			}
			else
			{
				mysql_query("UPDATE `".$config['db']['pre']."providers` SET `provider_password` = '".md5($password)."' WHERE `provider_id` =".validate_input($id)." LIMIT 1 ;");
				message($lang['CHANGED_PASSWORD'], $config,$lang, 'manage.php');
				exit();
			}
	}
	else
	{
			$error = 0;
			$error_msg = array();			
			$email_info = mysql_fetch_row(mysql_query("SELECT buyer_id FROM ".$config['db']['pre']."buyers WHERE buyer_id='".$_SESSION['user']['id']."' LIMIT 1"));
			if(!isset($email_info[0]))
			{
				$error++;
				$error_msg[] = '';
			}
			//echo "$error";exit();
			if($error > 0)
			{
				message($lang['ERROR_CHANGE_PASSWORD'], $config,$lang, 'profile_edit.php');
			}
			else
			{
				mysql_query("UPDATE `".$config['db']['pre']."buyers` SET `buyer_password` = '".md5($password)."' WHERE `buyer_id` =".validate_input($id)." LIMIT 1 ;");
				message($lang['CHANGED_PASSWORD'], $config,$lang, 'manage.php');
				exit();
			}
	}
}
else
{
	header("Location: login.php");
	exit;
}
?>